<template>
  <div class="cml-detail"
    :style="{width: width + 'px'}">
    <div class="cml-detail-title">
      <div class="close-area">
        <button class="close-btn"
          title="close"
          @click="closeDetailPanel"></button>
      </div>
      <div class="title-area">
        <p class="title-text">{{ titleMore }}</p>
      </div>
    </div>
    <!-- 内容分发 -->
    <div class="cml-detail-content-wrap">
      <div class="cml-detail-content">
        <slot></slot>
      </div>
    </div>
  </div>
</template>
<script>
import Bus from '../util/bus'

export default {
  name: 'DetailBox',
  components: {},
  model: {},
  props: {
    titleMore: {
      type: String,
      default: '功能详情'
    },
    width: {
      type: Number,
      default: 300
    },
    showControl: {
      type: Boolean
    }
  },
  data() {
    return {}
  },
  computed: {},
  watch: {},
  created() {
    Bus.$on('close', this.handleClose)
  },
  mounted() {
    Bus.$emit('close', this._uid)
    this.$emit('change', true)
  },
  beforeDestroy() {
    Bus.$off('close', this.handleClose)
    this.$emit('change', false)
  },
  methods: {
    // 关闭控制面板
    closeDetailPanel() {
      this.$emit('update:showControl', false)
    },
    // 关闭面板控制
    handleClose(msg) {
      if (this._uid !== msg) {
        this.$emit('update:showControl', false)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
@import '../style/panel-var.scss';
@import '../style/panel-mixin.scss';

.#{$prefix-s}-detail {
  position: fixed;
  top: 0;
  left: 300px;
  z-index: 1;

  width: $detail-box-w;
  height: 100vh;

  background-color: $bg-active;

  box-shadow: 4px 0 5px #0000008a;
  .#{$prefix-s}-detail-title {
    margin: 30px 20px 0;
    color: $text-color;

    .close-area {
      @include flex(row, flex-end);
      .close-btn {
        position: relative;
        color: $line-color;
        width: 25px;
        height: 25px;
        box-sizing: border-box;
        border: 1px solid currentColor;
        border-radius: 50%;

        background-color: transparent;
        transition: all ease 0.2s;
        &:after,
        &:before {
          content: '';
          display: block;
          width: 1px;
          height: 13px;
          background-color: currentColor;
        }
        &:before {
          transform: translateX(11px) translateY(5px) rotate(45deg);
        }
        &::after {
          transform: translateX(11px) translateY(-8px) rotate(-45deg);
        }
        &:hover, &:focus {
          color: $text-active-color;
        }
      }
    }
    .title-area {
      height: 45px;
      box-sizing: border-box;
      border-bottom: 1px solid $line-color;
      display: flex;
      align-items: center;
      .title-text {
        position: relative;
        padding-left: 8px;
        text-align: left;
        &:before {
          content: '';
          display: inline-block;
          height: 1em;
          width: 2px;
          background: $text-active-color;
          position: absolute;
          top: 2px;
          left: 0px;
        }
      }
    }
  }
  .cml-detail-content-wrap {
    color: #c1fffb;
    overflow-y: auto;
    overflow-x: hidden;
    height: calc(100% - 100px);
    &::-webkit-scrollbar {
      width: 6px;
    }

    &::-webkit-scrollbar-thumb {
      height: 56px;
      background-color: hsla(0, 0%, 53%, 0.4);
    }
    &::-webkit-scrollbar-track {
      background-color: hsla(0, 0%, 53%, 0.2);
    }
    .cml-detail-content {
      width: 100%;
    }
  }
}
</style>
